package com.zmn.oms.services.impl.highopinion;

import com.zmn.base.plat.engine.common.constant.PlatEngineConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.consts.GlobalConsts;
import com.zmn.oms.model.entity.highopinion.OmsMasterHighOpinion;
import com.zmn.oms.model.entity.highopinion.OmsMasterHighOpinionQuery;
import com.zmn.oms.persistence.interfaces.highopinion.OmsMasterHighOpinionDao;
import com.zmn.oms.services.interfaces.highopinion.OmsMasterHighOpinionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 接口实现类
 *
 * @author yangshuangping
 * @since 2022/09/13 10:48
 */
@Slf4j
@Service
public class OmsMasterHighOpinionServiceImpl implements OmsMasterHighOpinionService {

    private static final String TAG = "基础服务接口";

    @Resource
    private OmsMasterHighOpinionDao omsMasterHighOpinionDao;

    @Override
    public OmsMasterHighOpinion findById(Integer masterId) {
        if (Objects.isNull(masterId)) {
            log.error("[{}],根据id查询数据masterId为null", TAG);
            return null;
        }
        return omsMasterHighOpinionDao.findById(masterId);
    }

    @Override
    public List<OmsMasterHighOpinion> listByIds(List<Integer> masterIds) {
        if (CollectionUtils.isEmpty(masterIds)) {
            log.error("[{}],按条件查询数据,masterIds为null", TAG);
            return Collections.emptyList();
        }
        return omsMasterHighOpinionDao.listByIds(masterIds);
    }

    @Override
    public List<OmsMasterHighOpinion> listByQuery(OmsMasterHighOpinionQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        return omsMasterHighOpinionDao.listByQuery(query);
    }

    @Override
    public List<OmsMasterHighOpinion> listPageByQuery(OmsMasterHighOpinionQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        if (NumberUtil.isNullOrZero(query.getTotalCount())) {
            query.setTotalCount(countByQuery(query));
        }
        return omsMasterHighOpinionDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(OmsMasterHighOpinionQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsMasterHighOpinionDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(OmsMasterHighOpinion omsMasterHighOpinion) {
        if (Objects.isNull(omsMasterHighOpinion.getMasterId())) {
            log.error("[{}],根据id修改数据,omsMasterHighOpinion为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsMasterHighOpinionDao.updateByKey(omsMasterHighOpinion);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, PlatEngineConsts.NO) && !Objects.equals(status, PlatEngineConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        omsMasterHighOpinionDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(OmsMasterHighOpinion omsMasterHighOpinion) {
        if (Objects.isNull(omsMasterHighOpinion)) {
            log.error("[{}],新增数据,omsMasterHighOpinion为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsMasterHighOpinionDao.insert(omsMasterHighOpinion);
    }

    @Override
    public Integer deleteByKey(Integer masterId) {
        if (Objects.isNull(masterId)) {
            log.error("[{}],根据id删除数据,masterId为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsMasterHighOpinionDao.deleteByKey(masterId);
    }
}